package ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;


import messageprocessors.clients.Terminal;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class LoginGui extends javax.swing.JFrame {
	private JTextField jTextField1;
	private JPasswordField jPasswordField1;
	private JButton jButton1;
	private JButton jButton2;
	private JLabel jLabel3;
	private JLabel jLabel2;
	private JLabel jLabel1;
	public Terminal client;
	public TerminalUI terui;
	public TerminalGuiAdmin gui;

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				LoginGui inst = new LoginGui();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public LoginGui() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				jTextField1 = new JTextField();
				getContentPane().add(jTextField1);
				jTextField1.setBounds(110, 64, 283, 23);
			}
			{
				jPasswordField1 = new JPasswordField();
				getContentPane().add(jPasswordField1);
				jPasswordField1.setBounds(110, 99, 283, 23);
			}
			{
				jLabel1 = new JLabel();
				getContentPane().add(jLabel1);
				jLabel1.setText("Username");
				jLabel1.setBounds(19, 67, 79, 16);
			}
			{
				jLabel2 = new JLabel();
				getContentPane().add(jLabel2);
				jLabel2.setText("Login");
				jLabel2.setBounds(164, 21, 107, 16);
			}
			{
				jLabel3 = new JLabel();
				getContentPane().add(jLabel3);
				jLabel3.setText("Userpw");
				jLabel3.setBounds(19, 102, 79, 16);
			}
			{
				jButton1 = new JButton();
				getContentPane().add(jButton1);
				jButton1.setText("Einloggen");
				jButton1.addActionListener(new ActionListener(){
					@SuppressWarnings("deprecation")
					public void actionPerformed(ActionEvent e)
			        {
					  if (jTextField1.getText().trim().equals("admin")){	
					  try {
						  System.out.println("hierstream");
						client=new Terminal(jTextField1.getText(),jPasswordField1.getText());
						client.connect();
					  } catch (Exception ex) {
						  
					  }
						 if (client.connection.isAuthenticated()==true){
				     	     
							 client.disconnect();
							 setVisible(false);
							 terui=new TerminalUI(0,jTextField1.getText(),jPasswordField1.getText());
							 
				     	 }else if (client.connection.isAuthenticated()==false){
				     			
				     	 }	
					  
			        }else{
			        	try {
							client=new Terminal(jTextField1.getText(),jPasswordField1.getText());
							client.connect();
						  } catch (Exception ex) {
							  
						  }
							 if (client.connection.isAuthenticated()==true){
					     	     
								 client.disconnect();
								 setVisible(false);
								 terui=new TerminalUI(1,jTextField1.getText(),jPasswordField1.getText());
								 
					     	 }else if (client.connection.isAuthenticated()==false){
					     			
					     	 }	
						  
				        }
				       
			        }
				});
				jButton1.setBounds(110, 153, 113, 49);
			}
			{
				jButton2 = new JButton();
				getContentPane().add(jButton2);
				jButton2.setText("Beenden");
				jButton2.addActionListener(new ActionListener()
				{
					public void actionPerformed(ActionEvent e)
			        {
							System.exit(0);
			        }
				});
				jButton2.setBounds(271, 153, 122, 49);
			}
			pack();
			this.setSize(532, 364);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}

}
